package com.lagou.homework04;

import java.io.*;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Test02 {

    public static void main(String[] args) {

        BufferedReader bs = null;
        BufferedWriter bw = null;
        try {
            bs = new BufferedReader(new InputStreamReader(System.in));
            List<String> list = new ArrayList();
            while (true) {
                System.out.println("请输入字符串：");
                String s = bs.readLine();
                if ("end".equals(s)) {
                    System.out.println("输入结束！");
                    break;
                } else {
                    list.add(s);
                }
            }
            System.out.println("排序前：" + list);
            Collections.sort(list,Collections.reverseOrder());
            System.out.println("排序后：" + list);
            bw = new BufferedWriter(new FileWriter("f:/abc.txt"));
            for(String ss : list) {
                bw.write(ss);
                bw.newLine();
            }
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (null != bw) {
                try {
                    bw.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            if (null != bs) {
                try {
                    bs.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}
